package idv.takeshi.software.productline.bookstore.domain.model.order;

import java.util.Date;

import java.math.BigDecimal;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;


/**
 * A abstract super payment for every kind of payments.
 * @author takeshi
 *
 */
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class Payment {
	
	@Id
    @GeneratedValue(strategy = GenerationType.TABLE)
	private Long id;
	
	@Column(nullable = false)
	private boolean paid;
	
	@Column(nullable = false, name = "UPDATE_TIME")
	private Date updateTime;
	
	@Column(nullable = false)
	private BigDecimal amount;
	 
	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}


	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}


	/**
	 * @param paid the paid to set
	 */
	public void setPaid(boolean paid) {
		this.paid = paid;
	}


	/**
	 * Is paid ?
	 * @return
	 */
	public boolean isPaid() {
		return this.paid;
	}


	/**
	 * @return the updateTime
	 */
	public Date getUpdateTime() {
		return updateTime;
	}


	/**
	 * @param updateTime the updateTime to set
	 */
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}


	/**
	 * @return the amount
	 */
	public BigDecimal getAmount() {
		return amount;
	}


	/**
	 * @param amount the amount to set
	 */
	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}


	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj == null) { return false; }
		   if (obj == this) { return true; }
		   if (!(obj instanceof Payment)) {
		     return false;
		   }
		   Payment rhs = (Payment) obj;
		   return new EqualsBuilder()
			   .append(this.id, rhs.id)
			   .append(this.paid, rhs.paid)
			   .append(this.updateTime, rhs.updateTime)
			   .append(this.amount, rhs.amount)
		       .isEquals();
	}


	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return new HashCodeBuilder(43, 47).
	       append(this.id).
	       append(this.paid).
	       append(this.updateTime).
	       append(this.amount).
	       toHashCode();
	}


	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
	}
	 
}
 
